using System.Collections.Generic;
using System.IO;

namespace MedicalManagementSystem.Utils
{
    using System;
    using System.Linq;
    using System.Xml;
    using CarlosAg.ExcelXmlWriter;
    using MedicalManagementSystem.Models;
    
    public class StatisticsReport
    {
        #region private members
        private class PatientChartDiagnos
        {
            public Patient Patient {get; private set;}
            public IEnumerable<PatientChart> PatientCharts {get; private set;}
            public IEnumerable<Diagnos> Diagnosis { get; private set; }
            public PatientChartDiagnos(Patient patient, IEnumerable<PatientChart> patientCharts)
            {
                Patient = patient;
                PatientCharts = patientCharts;
                Diagnosis = GetDiagnos();
            }

            private IEnumerable<Diagnos> GetDiagnos()
            {
                var result = new List<Diagnos>();
                foreach (var pchart in PatientCharts)
                {
                    
                    pchart.LoadDiseaseNotes();
                    var diseaseNotes = DbContext.Instance.PatientChart.Where(pch => pch.id == pchart.id).Select(pch => pch.DiseaseNotes).
                        ToList();
                    foreach (var diseaseNote in diseaseNotes)
                    {
                        diseaseNote.Load();
                        var intermediateDiagnos = diseaseNote.Select(d => d.Diagnos);
                        //if (result.Count > 0)
                        //{
                            //result.Concat(diseaseNote.Select(d => d.Diagnos).ToList());
                            //result = result.Concat();
                        //}
                       // else 
                        result.AddRange(intermediateDiagnos);
                    }

                }
                return result;
            }
        }    
        
        private DateTime dateStart;
        private DateTime dateEnd;
        #endregion

        public StatisticsReport(DateTime dateStart, DateTime dateEnd)
        {
            this.dateStart = dateStart;
            this.dateEnd = dateEnd;
        }
        public void Generate(Stream stream)
        {
            Workbook wBook = GenerateWorkbook();
            wBook.Save(stream);
        }
        public Workbook GenerateWorkbook()
        {
            Workbook book = new Workbook();
            // -----------------------------------------------
            //  Properties
            // -----------------------------------------------
            book.Properties.Author = "MMS";
            book.Properties.LastAuthor = "Andre";
            book.Properties.Created = new System.DateTime(2011, 2, 12, 18, 58, 59, 0);
            book.Properties.LastSaved = new System.DateTime(2011, 2, 12, 22, 50, 13, 0);
            book.Properties.Version = "12.00";
            book.ExcelWorkbook.WindowHeight = 8955;
            book.ExcelWorkbook.WindowWidth = 15195;
            book.ExcelWorkbook.WindowTopX = 480;
            book.ExcelWorkbook.WindowTopY = 15;
            book.ExcelWorkbook.ProtectWindows = false;
            book.ExcelWorkbook.ProtectStructure = false;
            // -----------------------------------------------
            //  Generate Styles
            // -----------------------------------------------
            this.GenerateStyles(book.Styles);
            // -----------------------------------------------
            //  Generate Sheet2 Worksheet
            // -----------------------------------------------
            this.GenerateWorksheetSheet2(book.Worksheets);

            // -----------------------------------------------
            
            //need swap Worksheets
            //var tempW = book.Worksheets[book.Worksheets.Count - 1];
            //book.Worksheets.Remove(book.Worksheets[book.Worksheets.Count - 1]);
            //book.Worksheets.Insert(1, tempW);

            return book;
        }
        
        private void GenerateStyles(WorksheetStyleCollection styles) {
            // -----------------------------------------------
            //  Default
            // -----------------------------------------------
            WorksheetStyle Default = styles.Add("Default");
            Default.Name = "Normal";
            Default.Font.FontName = "Calibri";
            Default.Font.Size = 11;
            Default.Font.Color = "#000000";
            Default.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            // -----------------------------------------------
            //  m82182592
            // -----------------------------------------------
            WorksheetStyle m82182592 = styles.Add("m82182592");
            m82182592.Font.FontName = "Times New Roman";
            m82182592.Font.Size = 9;
            m82182592.Font.Color = "#000000";
            m82182592.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182592.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182592.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182592.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182592.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182592.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182612
            // -----------------------------------------------
            WorksheetStyle m82182612 = styles.Add("m82182612");
            m82182612.Font.FontName = "Times New Roman";
            m82182612.Font.Size = 9;
            m82182612.Font.Color = "#000000";
            m82182612.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182612.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182612.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182612.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182612.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182612.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182144
            // -----------------------------------------------
            WorksheetStyle m82182144 = styles.Add("m82182144");
            m82182144.Font.FontName = "Times New Roman";
            m82182144.Font.Size = 9;
            m82182144.Font.Color = "#000000";
            m82182144.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182144.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182144.Alignment.WrapText = true;
            m82182144.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182144.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182144.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182144.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182164
            // -----------------------------------------------
            WorksheetStyle m82182164 = styles.Add("m82182164");
            m82182164.Font.FontName = "Times New Roman";
            m82182164.Font.Size = 9;
            m82182164.Font.Color = "#000000";
            m82182164.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182164.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182164.Alignment.WrapText = true;
            m82182164.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182164.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182164.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182164.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182184
            // -----------------------------------------------
            WorksheetStyle m82182184 = styles.Add("m82182184");
            m82182184.Font.FontName = "Times New Roman";
            m82182184.Font.Size = 9;
            m82182184.Font.Color = "#000000";
            m82182184.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182184.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182184.Alignment.WrapText = true;
            m82182184.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182184.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182184.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182184.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182204
            // -----------------------------------------------
            WorksheetStyle m82182204 = styles.Add("m82182204");
            m82182204.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182204.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182204.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182204.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182204.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182204.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182224
            // -----------------------------------------------
            WorksheetStyle m82182224 = styles.Add("m82182224");
            m82182224.Font.FontName = "Times New Roman";
            m82182224.Font.Size = 9;
            m82182224.Font.Color = "#000000";
            m82182224.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182224.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182224.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182224.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182224.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182224.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182244
            // -----------------------------------------------
            WorksheetStyle m82182244 = styles.Add("m82182244");
            m82182244.Font.FontName = "Times New Roman";
            m82182244.Font.Size = 9;
            m82182244.Font.Color = "#000000";
            m82182244.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182244.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182244.Alignment.WrapText = true;
            m82182244.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182244.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182244.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182244.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182264
            // -----------------------------------------------
            WorksheetStyle m82182264 = styles.Add("m82182264");
            m82182264.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182264.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182264.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182264.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182264.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182264.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182284
            // -----------------------------------------------
            WorksheetStyle m82182284 = styles.Add("m82182284");
            m82182284.Font.FontName = "Times New Roman";
            m82182284.Font.Size = 9;
            m82182284.Font.Color = "#000000";
            m82182284.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182284.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182284.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182284.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182284.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182284.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182304
            // -----------------------------------------------
            WorksheetStyle m82182304 = styles.Add("m82182304");
            m82182304.Font.FontName = "Times New Roman";
            m82182304.Font.Size = 9;
            m82182304.Font.Color = "#000000";
            m82182304.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182304.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182304.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182304.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182304.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182304.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  m82182324
            // -----------------------------------------------
            WorksheetStyle m82182324 = styles.Add("m82182324");
            m82182324.Font.FontName = "Times New Roman";
            m82182324.Font.Size = 9;
            m82182324.Font.Color = "#000000";
            m82182324.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            m82182324.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            m82182324.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            m82182324.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            m82182324.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            m82182324.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  s127
            // -----------------------------------------------
            WorksheetStyle s127 = styles.Add("s127");
            s127.Font.FontName = "Times New Roman";
            s127.Font.Size = 9;
            s127.Font.Color = "#000000";
            s127.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            s127.Alignment.WrapText = true;
            // -----------------------------------------------
            //  s204
            // -----------------------------------------------
            WorksheetStyle s204 = styles.Add("s204");
            s204.Font.FontName = "Times New Roman";
            s204.Font.Size = 9;
            s204.Font.Color = "#000000";
            // -----------------------------------------------
            //  s216
            // -----------------------------------------------
            WorksheetStyle s216 = styles.Add("s216");
            s216.Font.FontName = "Times New Roman";
            s216.Font.Size = 9;
            s216.Font.Color = "#000000";
            s216.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            s216.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            s216.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            s216.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  s287
            // -----------------------------------------------
            WorksheetStyle s287 = styles.Add("s287");
            s287.Font.FontName = "Times New Roman";
            s287.Font.Size = 9;
            s287.Font.Color = "#000000";
            s287.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            s287.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            s287.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            s287.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            s287.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            s287.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);
            // -----------------------------------------------
            //  s307
            // -----------------------------------------------
            WorksheetStyle s307 = styles.Add("s307");
            s307.Font.FontName = "Times New Roman";
            s307.Font.Size = 9;
            s307.Font.Color = "#000000";
            s307.Alignment.Horizontal = StyleHorizontalAlignment.Center;
            s307.Alignment.Vertical = StyleVerticalAlignment.Bottom;
            s307.Alignment.WrapText = true;
            s307.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1);
            s307.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1);
            s307.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1);
            s307.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1);

        }

        
        private void GenerateWorksheetSheet2(WorksheetCollection sheets)
        {

            #region defaultGenerateWorksheet
            Worksheet sheet = sheets.Add("Sheet2");
            sheet.Table.DefaultRowHeight = 15F;
            sheet.Table.ExpandedColumnCount = 16;
            sheet.Table.ExpandedRowCount = 49;
            sheet.Table.FullColumns = 1;
            sheet.Table.FullRows = 1;
            WorksheetColumn column0 = sheet.Table.Columns.Add();
            column0.Index = 2;
            column0.Width = 126;
            column0.StyleID = "s204";
            WorksheetColumn column1 = sheet.Table.Columns.Add();
            column1.Width = 79;
            column1.StyleID = "s204";
            WorksheetColumn column2 = sheet.Table.Columns.Add();
            column2.StyleID = "s204";
            column2.Span = 12;
            // -----------------------------------------------
            WorksheetRow Row0 = sheet.Table.Rows.Add();
            Row0.AutoFitHeight = false;
            // -----------------------------------------------
            WorksheetRow Row1 = sheet.Table.Rows.Add();
            Row1.AutoFitHeight = false;
            WorksheetCell cell;
            cell = Row1.Cells.Add();
            cell.StyleID = "m82182144";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Наименование заболевания";
            cell.Index = 2;
            cell.MergeDown = 3;
            cell = Row1.Cells.Add();
            cell.StyleID = "m82182164";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Шифр по МКБ-10";
            cell.MergeDown = 3;
            cell = Row1.Cells.Add();
            cell.StyleID = "m82182184";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Номер строки";
            cell.MergeDown = 3;
            cell = Row1.Cells.Add();
            cell.StyleID = "m82182204";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Зарегистрировано больных в течение года";
            cell.MergeAcross = 11;
            // -----------------------------------------------
            WorksheetRow Row2 = sheet.Table.Rows.Add();
            Row2.AutoFitHeight = false;
            cell = Row2.Cells.Add();
            cell.StyleID = "m82182224";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "всего";
            cell.Index = 5;
            cell.MergeDown = 2;
            cell = Row2.Cells.Add();
            cell.StyleID = "m82182244";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "из них женщин";
            cell.MergeDown = 2;
            cell = Row2.Cells.Add();
            cell.StyleID = "m82182264";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "в том числе в возрасте, лет (из графы)";
            cell.MergeAcross = 9;
            // -----------------------------------------------
            WorksheetRow Row3 = sheet.Table.Rows.Add();
            Row3.AutoFitHeight = false;
            cell = Row3.Cells.Add();
            cell.StyleID = "m82182284";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "0-17";
            cell.Index = 7;
            cell.MergeAcross = 1;
            cell = Row3.Cells.Add();
            cell.StyleID = "m82182304";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "18-19";
            cell.MergeAcross = 1;
            cell = Row3.Cells.Add();
            cell.StyleID = "m82182324";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "20-39";
            cell.MergeAcross = 1;
            cell = Row3.Cells.Add();
            cell.StyleID = "m82182592";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "40-59";
            cell.MergeAcross = 1;
            cell = Row3.Cells.Add();
            cell.StyleID = "m82182612";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "60 и старше";
            cell.MergeAcross = 1;
            // -----------------------------------------------
            WorksheetRow Row4 = sheet.Table.Rows.Add();
            Row4.Height = 26;
            Row4.AutoFitHeight = false;
            cell = Row4.Cells.Add();
            cell.StyleID = "s307";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "всего";
            cell.Index = 7;
            Row4.Cells.Add("из них женщин", DataType.String, "s307");
            Row4.Cells.Add("всего", DataType.String, "s307");
            Row4.Cells.Add("из них женщин", DataType.String, "s307");
            Row4.Cells.Add("всего", DataType.String, "s307");
            Row4.Cells.Add("из них женщин", DataType.String, "s307");
            Row4.Cells.Add("всего", DataType.String, "s307");
            Row4.Cells.Add("из них женщин", DataType.String, "s307");
            Row4.Cells.Add("всего", DataType.String, "s307");
            Row4.Cells.Add("из них женщин", DataType.String, "s307");
            // -----------------------------------------------
            WorksheetRow Row5 = sheet.Table.Rows.Add();
            Row5.AutoFitHeight = false;
            cell = Row5.Cells.Add();
            cell.StyleID = "s216";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "А";
            cell.Index = 2;
            Row5.Cells.Add("Б", DataType.String, "s216");
            Row5.Cells.Add("В", DataType.String, "s216");
            Row5.Cells.Add("1", DataType.Number, "s216");
            Row5.Cells.Add("2", DataType.Number, "s216");
            Row5.Cells.Add("3", DataType.Number, "s216");
            Row5.Cells.Add("4", DataType.Number, "s216");
            Row5.Cells.Add("5", DataType.Number, "s216");
            Row5.Cells.Add("6", DataType.Number, "s216");
            Row5.Cells.Add("7", DataType.Number, "s216");
            Row5.Cells.Add("8", DataType.Number, "s216");
            Row5.Cells.Add("9", DataType.Number, "s216");
            Row5.Cells.Add("10", DataType.Number, "s216");
            Row5.Cells.Add("11", DataType.Number, "s216");
            Row5.Cells.Add("12", DataType.Number, "s216");
            // -----------------------------------------------
            WorksheetRow Row6 = sheet.Table.Rows.Add();
            Row6.Height = 29;
            Row6.AutoFitHeight = false;
            cell = Row6.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Психические расстройства - всего ……………………..";
            cell.Index = 2;
            Row6.Cells.Add("F00-F09, F20-F99", DataType.String, "s127");
            cell = Row6.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "1";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            cell = Row6.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row7 = sheet.Table.Rows.Add();
            Row7.Height = 60;
            Row7.AutoFitHeight = false;
            cell = Row7.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "в том числе: органические заболевания, включая симптоматические (соматогенные) пс" +
                "ихические расстройства …………….";
            cell.Index = 2;
            cell = Row7.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F00-F09";
            cell = Row7.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "2";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            cell = Row7.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row8 = sheet.Table.Rows.Add();
            Row8.Height = 31;
            Row8.AutoFitHeight = false;
            cell = Row8.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "органические психозы и (или) слабоумие";
            cell.Index = 2;
            Row8.Cells.Add("F00-F05, F06 (часть), F09", DataType.String, "s127");
            cell = Row8.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "3";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            cell = Row8.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row9 = sheet.Table.Rows.Add();
            Row9.Height = 35;
            Row9.AutoFitHeight = false;
            cell = Row9.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "из них: сосудистая деменция и другие формы старческого слабоумия";
            cell.Index = 2;
            cell = Row9.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F00-F01, F02, F03";
            cell = Row9.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "4";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            cell = Row9.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row10 = sheet.Table.Rows.Add();
            Row10.Height = 97;
            Row10.AutoFitHeight = false;
            cell = Row10.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "психозы и (или) слабоумие вследствие эпилепсии";
            cell.Index = 2;
            Row10.Cells.Add("F02.802*-F02.842*, F04.2, F05.02, F05.12, F05.82, F05.92, F06.02, F06.12, F06.22," +
                    " F06.302, F06.312, F06.322, F06.332, F06.812, F06.912", DataType.String, "s127");
            cell = Row10.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "5";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            cell = Row10.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row11 = sheet.Table.Rows.Add();
            Row11.Height = 36;
            cell = Row11.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "органические непсихотические расстройства";
            cell.Index = 2;
            cell = Row11.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F06 (часть), F07";
            cell = Row11.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "6";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            cell = Row11.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row12 = sheet.Table.Rows.Add();
            Row12.Height = 24;
            cell = Row12.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "из них обусловленные эпилепсией";
            cell.Index = 2;
            Row12.Cells.Add("F06 (часть), F07.2, F07.82, F07.92", DataType.String, "s127");
            cell = Row12.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "7";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            cell = Row12.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row13 = sheet.Table.Rows.Add();
            Row13.Height = 18;
            Row13.AutoFitHeight = false;
            cell = Row13.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "шизофрения";
            cell.Index = 2;
            cell = Row13.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F20";
            cell = Row13.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "8";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            cell = Row13.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row14 = sheet.Table.Rows.Add();
            Row14.Height = 18;
            Row14.AutoFitHeight = false;
            cell = Row14.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "шизотипическое расстройство";
            cell.Index = 2;
            cell = Row14.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F21";
            cell = Row14.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "9";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            cell = Row14.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row15 = sheet.Table.Rows.Add();
            Row15.Height = 18;
            Row15.AutoFitHeight = false;
            cell = Row15.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "шизоаффективные расстройства";
            cell.Index = 2;
            cell = Row15.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F25";
            cell = Row15.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "10";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            cell = Row15.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row16 = sheet.Table.Rows.Add();
            Row16.Height = 24;
            cell = Row16.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "острые и приходящие неорганические психозы";
            cell.Index = 2;
            cell = Row16.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F23, F24";
            cell = Row16.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "11";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            cell = Row16.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row17 = sheet.Table.Rows.Add();
            Row17.Height = 36;
            cell = Row17.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "хронические неорганические психозы, детские психозы";
            cell.Index = 2;
            Row17.Cells.Add("F22, F28, F29, F80.31, F84.0-4, F99", DataType.String, "s127");
            cell = Row17.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "12";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            cell = Row17.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row18 = sheet.Table.Rows.Add();
            Row18.Height = 18;
            Row18.AutoFitHeight = false;
            cell = Row18.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "аффективные психозы";
            cell.Index = 2;
            cell = Row18.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F30-F39 (часть)";
            cell = Row18.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "13";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            cell = Row18.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row19 = sheet.Table.Rows.Add();
            Row19.Height = 36;
            cell = Row19.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "из них: аффективные психозы с неконгруэнтным аффекту бредом";
            cell.Index = 2;
            Row19.Cells.Add("F30.24, F31.24, F31.54, F32.34, F33.34", DataType.String, "s127");
            cell = Row19.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "14";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            cell = Row19.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row20 = sheet.Table.Rows.Add();
            Row20.Height = 24;
            cell = Row20.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "аффективные непсихотические расстройства";
            cell.Index = 2;
            cell = Row20.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F30-F39 (часть)";
            cell = Row20.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "15";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            cell = Row20.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row21 = sheet.Table.Rows.Add();
            Row21.Height = 36;
            cell = Row21.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "невротические, связанные со стрессом и соматормные расстройства";
            cell.Index = 2;
            cell = Row21.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F40-F48";
            cell = Row21.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "16";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            cell = Row21.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row22 = sheet.Table.Rows.Add();
            Row22.Height = 48;
            cell = Row22.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "поведенческие синдромы, непсихотические расстройства детского и подросткового воз" +
                "раста";
            cell.Index = 2;
            Row22.Cells.Add("F50-F59, F80-F83, F84.5-F89, F90- F98, F99.2-F99.9", DataType.String, "s127");
            cell = Row22.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "17";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            cell = Row22.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row23 = sheet.Table.Rows.Add();
            Row23.Height = 24;
            cell = Row23.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "расстройства личности и поведения у взрослых";
            cell.Index = 2;
            cell = Row23.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F60-F69";
            cell = Row23.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "18";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            cell = Row23.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row24 = sheet.Table.Rows.Add();
            Row24.Height = 24;
            cell = Row24.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "умственная отсталость легкой степени";
            cell.Index = 2;
            cell = Row24.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F70";
            cell = Row24.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "19";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            cell = Row24.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row25 = sheet.Table.Rows.Add();
            Row25.Height = 24;
            cell = Row25.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "другие формы умственной отсталости";
            cell.Index = 2;
            cell = Row25.Cells.Add();
            cell.Data.Type = DataType.String;
            cell.Data.Text = "F71-F79";
            cell = Row25.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "20";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            cell = Row25.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row26 = sheet.Table.Rows.Add();
            Row26.Height = 36;
            cell = Row26.Cells.Add();
            cell.StyleID = "s127";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Психические расстройства , классифицированные в других рубриках МКБ-10";
            cell.Index = 2;
            Row26.Cells.Add("A52.1, A.81.0, B22.0, G10-G40 и другие", DataType.String, "s127");
            cell = Row26.Cells.Add();
            cell.Data.Type = DataType.Number;
            cell.Data.Text = "21";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            cell = Row26.Cells.Add();
            cell.StyleID = "s287";
            // -----------------------------------------------
            WorksheetRow Row27 = sheet.Table.Rows.Add();
            Row27.Index = 32;
            Row27.Height = 18;
            Row27.AutoFitHeight = false;
            #endregion

            GenerateRegisteredPatientsThisYear(sheet);
            sheet.Options.Selected = true;
            sheet.Options.ProtectObjects = false;
            sheet.Options.ProtectScenarios = false;
            sheet.Options.PageSetup.Header.Margin = 0.3F;
            sheet.Options.PageSetup.Footer.Margin = 0.3F;
            sheet.Options.PageSetup.PageMargins.Bottom = 0.75F;
            sheet.Options.PageSetup.PageMargins.Left = 0.7F;
            sheet.Options.PageSetup.PageMargins.Right = 0.7F;
            sheet.Options.PageSetup.PageMargins.Top = 0.75F;
            sheet.Options.Print.PaperSizeIndex = 9;
            sheet.Options.Print.VerticalResolution = 0;
            sheet.Options.Print.ValidPrinterInfo = true;

            sheet.Table.ExpandedColumnCount = 16;
            sheet.Table.ExpandedRowCount = 100;
            // -----------------------------------------------
            //  Options
            // -----------------------------------------------
            /*sheet.Options.Selected = true;
            sheet.Options.ProtectObjects = false;
            sheet.Options.ProtectScenarios = false;
            sheet.Options.PageSetup.Header.Margin = 0.3F;
            sheet.Options.PageSetup.Footer.Margin = 0.3F;
            sheet.Options.PageSetup.PageMargins.Bottom = 0.75F;
            sheet.Options.PageSetup.PageMargins.Left = 0.7F;
            sheet.Options.PageSetup.PageMargins.Right = 0.7F;
            sheet.Options.PageSetup.PageMargins.Top = 0.75F;*/
        }
        
        private void GenerateWorksheetSheet3(WorksheetCollection sheets) {
            Worksheet sheet = sheets.Add("Sheet3");
            sheet.Table.DefaultRowHeight = 15F;
            sheet.Table.ExpandedColumnCount = 14;
            sheet.Table.ExpandedRowCount = 11;
            sheet.Table.FullColumns = 1;
            sheet.Table.FullRows = 1;
            WorksheetColumn column0 = sheet.Table.Columns.Add();
            column0.Index = 8;
            column0.Width = 61;
            WorksheetColumn column1 = sheet.Table.Columns.Add();
            column1.Index = 12;
            column1.Width = 63;
            // -----------------------------------------------
            WorksheetRow Row0 = sheet.Table.Rows.Add();
            Row0.Index = 2;
            Row0.Height = 44;
            Row0.AutoFitHeight = false;
            WorksheetCell cell;
            cell = Row0.Cells.Add();
            cell.StyleID = "m55656036";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Наименование заболевания";
            cell.Index = 2;
            cell.MergeDown = 2;
            cell = Row0.Cells.Add();
            cell.StyleID = "m55655996";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Шифр по МКБ-10";
            cell.MergeDown = 2;
            cell = Row0.Cells.Add();
            cell.StyleID = "m55655936";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Номер строки";
            cell.MergeDown = 2;
            cell = Row0.Cells.Add();
            cell.StyleID = "m50792904";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Взято под наблюдение в отчётном году";
            cell.MergeAcross = 1;
            cell = Row0.Cells.Add();
            cell.StyleID = "m50792884";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Снято с наблюдения в отчётном году";
            cell.MergeAcross = 3;
            cell = Row0.Cells.Add();
            cell.StyleID = "m50792864";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Состоит под наблюдением на конец отчётного года";
            cell.MergeAcross = 3;
            // -----------------------------------------------
            WorksheetRow Row1 = sheet.Table.Rows.Add();
            cell = Row1.Cells.Add();
            cell.StyleID = "m55655956";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "диспансерное (ДУ)";
            cell.Index = 5;
            cell.MergeDown = 1;
            cell = Row1.Cells.Add();
            cell.StyleID = "m55655976";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "получающих лечебное-профилактическую помощь (КН)";
            cell.MergeDown = 1;
            cell = Row1.Cells.Add();
            cell.StyleID = "m50792984";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "диспансерного (ДУ)";
            cell.MergeAcross = 1;
            cell = Row1.Cells.Add();
            cell.StyleID = "m50792964";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "прекратили обращаться за лечебно-профилактической помощью (КН)";
            cell.MergeAcross = 1;
            cell = Row1.Cells.Add();
            cell.StyleID = "m50792944";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "диспансерного (ДУ)";
            cell.MergeAcross = 1;
            cell = Row1.Cells.Add();
            cell.StyleID = "m50792924";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "прекратили обращаться за лечебно-профилактической помощью (КН)";
            cell.MergeAcross = 1;
            // -----------------------------------------------
            WorksheetRow Row2 = sheet.Table.Rows.Add();
            Row2.Height = 120;
            cell = Row2.Cells.Add();
            cell.StyleID = "s98";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "всего";
            cell.Index = 7;
            Row2.Cells.Add("из них в связи с выздоровлением или стойким улучшением", DataType.String, "s98");
            Row2.Cells.Add("всего", DataType.String, "s98");
            Row2.Cells.Add("из них в связи с выздоровлением или стойким улучшением", DataType.String, "s98");
            Row2.Cells.Add("всего", DataType.String, "s98");
            Row2.Cells.Add("из них дети 0-17 лет", DataType.String, "s98");
            Row2.Cells.Add("всего", DataType.String, "s98");
            Row2.Cells.Add("из них дети 0-17 лет", DataType.String, "s98");
            // -----------------------------------------------
            WorksheetRow Row3 = sheet.Table.Rows.Add();
            cell = Row3.Cells.Add();
            cell.StyleID = "s98";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "А";
            cell.Index = 2;
            Row3.Cells.Add("Б", DataType.String, "s98");
            Row3.Cells.Add("В", DataType.String, "s98");
            Row3.Cells.Add("1", DataType.Number, "s98");
            Row3.Cells.Add("2", DataType.Number, "s98");
            Row3.Cells.Add("3", DataType.Number, "s98");
            Row3.Cells.Add("4", DataType.Number, "s98");
            Row3.Cells.Add("5", DataType.Number, "s98");
            Row3.Cells.Add("6", DataType.Number, "s98");
            Row3.Cells.Add("7", DataType.Number, "s98");
            Row3.Cells.Add("8", DataType.Number, "s98");
            Row3.Cells.Add("9", DataType.Number, "s98");
            Row3.Cells.Add("10", DataType.Number, "s98");
            // -----------------------------------------------
            WorksheetRow Row4 = sheet.Table.Rows.Add();
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell.Index = 2;
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            cell = Row4.Cells.Add();
            cell.StyleID = "s98";
            // -----------------------------------------------
            WorksheetRow Row5 = sheet.Table.Rows.Add();
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell.Index = 2;
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            cell = Row5.Cells.Add();
            cell.StyleID = "s98";
            // -----------------------------------------------
            WorksheetRow Row6 = sheet.Table.Rows.Add();
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell.Index = 2;
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            cell = Row6.Cells.Add();
            cell.StyleID = "s98";
            // -----------------------------------------------
            WorksheetRow Row7 = sheet.Table.Rows.Add();
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell.Index = 2;
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            cell = Row7.Cells.Add();
            cell.StyleID = "s98";
            // -----------------------------------------------
            WorksheetRow Row8 = sheet.Table.Rows.Add();
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell.Index = 2;
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            cell = Row8.Cells.Add();
            cell.StyleID = "s98";
            // -----------------------------------------------
            WorksheetRow Row9 = sheet.Table.Rows.Add();
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell.Index = 2;
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            cell = Row9.Cells.Add();
            cell.StyleID = "s98";
            // -----------------------------------------------
            //  Options
            // -----------------------------------------------
            sheet.Options.ProtectObjects = false;
            sheet.Options.ProtectScenarios = false;
            sheet.Options.PageSetup.Header.Margin = 0.3F;
            sheet.Options.PageSetup.Footer.Margin = 0.3F;
            sheet.Options.PageSetup.PageMargins.Bottom = 0.75F;
            sheet.Options.PageSetup.PageMargins.Left = 0.7F;
            sheet.Options.PageSetup.PageMargins.Right = 0.7F;
            sheet.Options.PageSetup.PageMargins.Top = 0.75F;
        }
        
        private void GenerateWorksheetSheet4(WorksheetCollection sheets) {
            Worksheet sheet = sheets.Add("Sheet4");
            sheet.Table.DefaultRowHeight = 15F;
            sheet.Table.ExpandedColumnCount = 13;
            sheet.Table.ExpandedRowCount = 18;
            sheet.Table.FullColumns = 1;
            sheet.Table.FullRows = 1;
            WorksheetColumn column0 = sheet.Table.Columns.Add();
            column0.Index = 10;
            column0.Width = 54;
            sheet.Table.Columns.Add(85);
            sheet.Table.Columns.Add(56);
            // -----------------------------------------------
            WorksheetRow Row0 = sheet.Table.Rows.Add();
            Row0.Index = 2;
            Row0.Height = 60;
            Row0.AutoFitHeight = false;
            WorksheetCell cell;
            cell = Row0.Cells.Add();
            cell.StyleID = "m52952432";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Наименование заболевания";
            cell.Index = 2;
            cell.MergeDown = 2;
            cell = Row0.Cells.Add();
            cell.StyleID = "m52952412";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Шифр по МКБ-10";
            cell.MergeDown = 2;
            cell = Row0.Cells.Add();
            cell.StyleID = "m52952392";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Номер строки";
            cell.MergeDown = 2;
            cell = Row0.Cells.Add();
            cell.StyleID = "m51133340";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Поступило больных, человек";
            cell.MergeAcross = 4;
            cell = Row0.Cells.Add();
            cell.StyleID = "m51133400";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Выбыло больных, человек";
            cell.MergeDown = 2;
            cell = Row0.Cells.Add();
            cell.StyleID = "m51133420";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Число койко-дней, проведённых в психиатрическом стационаре выбывшим больным";
            cell.MergeDown = 2;
            cell = Row0.Cells.Add();
            cell.StyleID = "m51133280";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Состоит на учёте на конец отчётного года, человек";
            cell.MergeAcross = 1;
            // -----------------------------------------------
            WorksheetRow Row1 = sheet.Table.Rows.Add();
            Row1.Height = 45;
            Row1.AutoFitHeight = false;
            cell = Row1.Cells.Add();
            cell.StyleID = "m51133380";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "всего";
            cell.Index = 5;
            cell.MergeAcross = 1;
            cell = Row1.Cells.Add();
            cell.StyleID = "m51133360";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "из них";
            cell.MergeAcross = 2;
            cell = Row1.Cells.Add();
            cell.StyleID = "m51133440";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "взрослых 18 лет и старше";
            cell.Index = 12;
            cell.MergeDown = 1;
            cell = Row1.Cells.Add();
            cell.StyleID = "m51133460";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "детей 0-17 лет";
            cell.MergeDown = 1;
            // -----------------------------------------------
            WorksheetRow Row2 = sheet.Table.Rows.Add();
            Row2.Height = 46;
            Row2.AutoFitHeight = false;
            cell = Row2.Cells.Add();
            cell.StyleID = "s118";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "взрослых 18 лет и старше";
            cell.Index = 5;
            Row2.Cells.Add("детей 0-17 лет", DataType.String, "s118");
            Row2.Cells.Add("впервые в данном году", DataType.String, "s118");
            Row2.Cells.Add("из них впервые в жизни", DataType.String, "s118");
            Row2.Cells.Add("принудительно", DataType.String, "s118");
            // -----------------------------------------------
            WorksheetRow Row3 = sheet.Table.Rows.Add();
            cell = Row3.Cells.Add();
            cell.StyleID = "s118";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "А";
            cell.Index = 2;
            Row3.Cells.Add("Б", DataType.String, "s118");
            Row3.Cells.Add("В", DataType.String, "s118");
            Row3.Cells.Add("1", DataType.Number, "s118");
            Row3.Cells.Add("2", DataType.Number, "s118");
            Row3.Cells.Add("3", DataType.Number, "s118");
            Row3.Cells.Add("4", DataType.Number, "s118");
            Row3.Cells.Add("5", DataType.Number, "s118");
            Row3.Cells.Add("6", DataType.Number, "s118");
            Row3.Cells.Add("7", DataType.Number, "s118");
            Row3.Cells.Add("8", DataType.Number, "s118");
            Row3.Cells.Add("9", DataType.Number, "s118");
            // -----------------------------------------------
            WorksheetRow Row4 = sheet.Table.Rows.Add();
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row5 = sheet.Table.Rows.Add();
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row6 = sheet.Table.Rows.Add();
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row7 = sheet.Table.Rows.Add();
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row8 = sheet.Table.Rows.Add();
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row9 = sheet.Table.Rows.Add();
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row10 = sheet.Table.Rows.Add();
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row11 = sheet.Table.Rows.Add();
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            cell = Row11.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row12 = sheet.Table.Rows.Add();
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            cell = Row12.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row13 = sheet.Table.Rows.Add();
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            cell = Row13.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row14 = sheet.Table.Rows.Add();
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            cell = Row14.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row15 = sheet.Table.Rows.Add();
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            cell = Row15.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row16 = sheet.Table.Rows.Add();
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            cell = Row16.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            //  Options
            // -----------------------------------------------
            sheet.Options.ProtectObjects = false;
            sheet.Options.ProtectScenarios = false;
            sheet.Options.PageSetup.Header.Margin = 0.3F;
            sheet.Options.PageSetup.Footer.Margin = 0.3F;
            sheet.Options.PageSetup.PageMargins.Bottom = 0.75F;
            sheet.Options.PageSetup.PageMargins.Left = 0.7F;
            sheet.Options.PageSetup.PageMargins.Right = 0.7F;
            sheet.Options.PageSetup.PageMargins.Top = 0.75F;
        }
        
        private void GenerateWorksheetSheet5(WorksheetCollection sheets) {
            Worksheet sheet = sheets.Add("Sheet5");
            sheet.Table.DefaultRowHeight = 15F;
            sheet.Table.ExpandedColumnCount = 16;
            sheet.Table.ExpandedRowCount = 12;
            sheet.Table.FullColumns = 1;
            sheet.Table.FullRows = 1;
            // -----------------------------------------------
            WorksheetRow Row0 = sheet.Table.Rows.Add();
            Row0.Index = 2;
            WorksheetCell cell;
            cell = Row0.Cells.Add();
            cell.StyleID = "m89603664";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Наименование заболеваний";
            cell.Index = 2;
            cell.MergeDown = 3;
            cell = Row0.Cells.Add();
            cell.StyleID = "m89603644";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Шифр по МКБ-10";
            cell.MergeDown = 3;
            cell = Row0.Cells.Add();
            cell.StyleID = "m89603624";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Номер строки";
            cell.MergeDown = 3;
            cell = Row0.Cells.Add();
            cell.StyleID = "m50793780";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Число больных, впервые признаных инвалидами в отчётном году";
            cell.MergeAcross = 5;
            cell = Row0.Cells.Add();
            cell.StyleID = "m50793760";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "Число больных, имеющих группу инвалидности на конец отчётного года";
            cell.MergeAcross = 5;
            // -----------------------------------------------
            WorksheetRow Row1 = sheet.Table.Rows.Add();
            cell = Row1.Cells.Add();
            cell.StyleID = "m89603604";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "всего";
            cell.Index = 5;
            cell.MergeDown = 2;
            cell = Row1.Cells.Add();
            cell.StyleID = "m89603584";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "из них женщин";
            cell.MergeDown = 2;
            cell = Row1.Cells.Add();
            cell.StyleID = "m50793900";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "из них (из графы 7)";
            cell.MergeAcross = 3;
            cell = Row1.Cells.Add();
            cell.StyleID = "m50793880";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "всего";
            cell.MergeDown = 2;
            cell = Row1.Cells.Add();
            cell.StyleID = "m50793860";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "из них женщин";
            cell.MergeDown = 2;
            cell = Row1.Cells.Add();
            cell.StyleID = "m50793800";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "из них (из графы 7)";
            cell.MergeAcross = 3;
            // -----------------------------------------------
            WorksheetRow Row2 = sheet.Table.Rows.Add();
            cell = Row2.Cells.Add();
            cell.StyleID = "m50793940";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "имевших III группу";
            cell.Index = 7;
            cell.MergeAcross = 1;
            cell = Row2.Cells.Add();
            cell.StyleID = "m50793920";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "инвалидов 0-17 лет";
            cell.MergeAcross = 1;
            cell = Row2.Cells.Add();
            cell.StyleID = "m50793840";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "имевших III группу";
            cell.Index = 13;
            cell.MergeAcross = 1;
            cell = Row2.Cells.Add();
            cell.StyleID = "m50793820";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "инвалидов 0-17 лет";
            cell.MergeAcross = 1;
            // -----------------------------------------------
            WorksheetRow Row3 = sheet.Table.Rows.Add();
            cell = Row3.Cells.Add();
            cell.StyleID = "s118";
            cell.Data.Type = DataType.String;
            cell.Data.Text = " женщин";
            cell.Index = 7;
            Row3.Cells.Add("из них", DataType.String, "s118");
            Row3.Cells.Add(" женщин", DataType.String, "s118");
            Row3.Cells.Add("из них", DataType.String, "s118");
            cell = Row3.Cells.Add();
            cell.StyleID = "s118";
            cell.Data.Type = DataType.String;
            cell.Data.Text = " женщин";
            cell.Index = 13;
            Row3.Cells.Add("из них", DataType.String, "s118");
            Row3.Cells.Add(" женщин", DataType.String, "s118");
            Row3.Cells.Add("из них", DataType.String, "s118");
            // -----------------------------------------------
            WorksheetRow Row4 = sheet.Table.Rows.Add();
            cell = Row4.Cells.Add();
            cell.StyleID = "s118";
            cell.Data.Type = DataType.String;
            cell.Data.Text = "А";
            cell.Index = 2;
            Row4.Cells.Add("Б", DataType.String, "s118");
            Row4.Cells.Add("В", DataType.String, "s118");
            Row4.Cells.Add("1", DataType.Number, "s118");
            Row4.Cells.Add("2", DataType.Number, "s118");
            Row4.Cells.Add("3", DataType.Number, "s118");
            Row4.Cells.Add("4", DataType.Number, "s118");
            Row4.Cells.Add("5", DataType.Number, "s118");
            Row4.Cells.Add("6", DataType.Number, "s118");
            Row4.Cells.Add("7", DataType.Number, "s118");
            Row4.Cells.Add("8", DataType.Number, "s118");
            Row4.Cells.Add("9", DataType.Number, "s118");
            Row4.Cells.Add("10", DataType.Number, "s118");
            Row4.Cells.Add("11", DataType.Number, "s118");
            Row4.Cells.Add("12", DataType.Number, "s118");
            // -----------------------------------------------
            WorksheetRow Row5 = sheet.Table.Rows.Add();
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            cell = Row5.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row6 = sheet.Table.Rows.Add();
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            cell = Row6.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row7 = sheet.Table.Rows.Add();
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            cell = Row7.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row8 = sheet.Table.Rows.Add();
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            cell = Row8.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row9 = sheet.Table.Rows.Add();
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            cell = Row9.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            WorksheetRow Row10 = sheet.Table.Rows.Add();
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell.Index = 2;
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            cell = Row10.Cells.Add();
            cell.StyleID = "s118";
            // -----------------------------------------------
            //  Options
            // -----------------------------------------------
            sheet.Options.ProtectObjects = false;
            sheet.Options.ProtectScenarios = false;
            sheet.Options.PageSetup.Header.Margin = 0.3F;
            sheet.Options.PageSetup.Footer.Margin = 0.3F;
            sheet.Options.PageSetup.PageMargins.Bottom = 0.75F;
            sheet.Options.PageSetup.PageMargins.Left = 0.7F;
            sheet.Options.PageSetup.PageMargins.Right = 0.7F;
            sheet.Options.PageSetup.PageMargins.Top = 0.75F;
        }
        
        private void GenerateRegisteredPatientsThisYear(Worksheet sheet)
        {
            var RowsFilter = GenerateRowsFilterPatientsThisYear();

            var allPatientCharts =
                DbContext.Instance.PatientChart.Where(
                    pchart => pchart.DateArrive >= dateStart && pchart.DateArrive <= dateEnd).Distinct().ToList();
            IEnumerable<Patient> patients = allPatientCharts.Each(ch => ch.LoadPatient()).Select(ch => ch.Patient).Distinct();
            var patientChartDiagnoses = patients.Select(patient => 
                new PatientChartDiagnos(patient, allPatientCharts.Where(pch => pch.Patient.id == patient.id))).ToList();
            int position = 6;
            foreach (var rowToFill in RowsFilter)
            {
                var allDiagnosis = new List<Diagnos>();
                int[] param = new int[12];
                int allCounter = 0;
                int allFemaleCounter = 0;
                int counter0_17 = 0;
                int femaleCounter0_17 = 0;
                int counter18_19 = 0;
                int femaleCounter18_19 = 0;
                int counter20_39 = 0;
                int femaleCounter20_39 = 0;
                int counter40_59 = 0;
                int femaleCounter40_59 = 0;
                int counter60 = 0;
                int femaleCounter60= 0;
                
                #region Computing
                foreach (var patientChartDiagnosis in patientChartDiagnoses)
                {
                    var CurrentPatientChartDiagnosis = rowToFill.Intersect(patientChartDiagnosis.Diagnosis);
                    allCounter += CurrentPatientChartDiagnosis.Count();
                    var Birth = patientChartDiagnosis.Patient.Birthday;
                    var Sex = patientChartDiagnosis.Patient.Sex;
                    if (Sex)
                    {
                        if ((dateEnd.Year - Birth.Year <= 17) && (Birth.Month < dateEnd.Month) &&
                            (Birth.Day < dateEnd.Day))
                        {
                            counter0_17 += CurrentPatientChartDiagnosis.Count();
                        }
                        else
                        {
                            if ((dateEnd.Year - Birth.Year <= 19) && (Birth.Month < dateEnd.Month) &&
                                (Birth.Day < dateEnd.Day))
                            {
                                counter18_19 += CurrentPatientChartDiagnosis.Count();
                            }
                            else
                            {
                                if ((dateEnd.Year - Birth.Year <= 39) && (Birth.Month < dateEnd.Month) &&
                                 (Birth.Day < dateEnd.Day))
                                {
                                    counter20_39 += CurrentPatientChartDiagnosis.Count();
                                } 
                                else
                                {
                                    if ((Birth.Year - dateEnd.Year <= 40) && (Birth.Month < dateEnd.Month) &&
                                     (Birth.Day < dateEnd.Day))
                                    {
                                        counter40_59 += CurrentPatientChartDiagnosis.Count();
                                    }
                                    else
                                    {
                                        counter60 += CurrentPatientChartDiagnosis.Count();   
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        allFemaleCounter += CurrentPatientChartDiagnosis.Count();
                        if ((dateEnd.Year - Birth.Year <= 17) && (Birth.Month < dateEnd.Month) &&
                            (Birth.Day < dateEnd.Day))
                        {
                            femaleCounter0_17 += CurrentPatientChartDiagnosis.Count();
                        }
                        else
                        {
                            if ((dateEnd.Year - Birth.Year <= 19) && (Birth.Month < dateEnd.Month) &&
                                (Birth.Day < dateEnd.Day))
                            {
                                femaleCounter18_19 += CurrentPatientChartDiagnosis.Count();
                            }
                            else
                            {
                                if ((dateEnd.Year - Birth.Year <= 39) && (Birth.Month < dateEnd.Month) &&
                                 (Birth.Day < dateEnd.Day))
                                {
                                    femaleCounter20_39 += CurrentPatientChartDiagnosis.Count();
                                }
                                else
                                {
                                    if ((Birth.Year - dateEnd.Year <= 40) && (Birth.Month < dateEnd.Month) &&
                                     (Birth.Day < dateEnd.Day))
                                    {
                                        femaleCounter40_59 += CurrentPatientChartDiagnosis.Count();
                                    }
                                    else
                                    {
                                        femaleCounter60 += CurrentPatientChartDiagnosis.Count();
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion

                int[] parameters = {allCounter, allFemaleCounter, counter0_17, femaleCounter0_17, counter18_19,
                                    femaleCounter18_19, counter20_39, femaleCounter20_39, counter40_59,
                                    femaleCounter40_59, counter60, femaleCounter60};
                WorksheetCell cell;
                WorksheetRow Row = sheet.Table.Rows[position];
                int pos = 3;
                for(int i = 0; i<parameters.Length; i++)
                {
                    cell = Row.Cells[pos];
                    cell.Data.Text = parameters[i] != 0 ? parameters[i].ToString() : string.Empty; 
                    pos++;
                }
                
                
                /*cell = Row.Cells[pos];
                
                cell.Data.Text = allCounter.ToString();
                
                pos++;

                cell = Row.Cells[pos];
                cell.Data.Text = allFemaleCounter.ToString();
                pos++;
                
                cell = Row.Cells[pos];
                cell.Data.Text = counter0_17.ToString();
                pos++;

                cell = Row.Cells[pos];
                cell.Data.Text = femaleCounter0_17.ToString();
                pos++;

                cell = Row.Cells[pos];
                
                cell.Data.Text = counter18_19.ToString();
                pos++;

                cell = Row.Cells[pos];
                cell.Data.Text = femaleCounter18_19.ToString();
                pos++;

                cell = Row.Cells[pos];
                
                cell.Data.Text = counter20_39.ToString();
                pos++;

                cell = Row.Cells[pos];
                cell.Data.Text = femaleCounter20_39.ToString();
                pos++;

                cell = Row.Cells[pos];
                cell.Data.Text = counter40_59.ToString();
                pos++;

                cell = Row.Cells[pos];
                cell.Data.Text = femaleCounter40_59.ToString();
                pos++;

                cell = Row.Cells[pos];
                cell.Data.Text = counter60.ToString();
                pos++;

                cell = Row.Cells[pos];
                cell.Data.Text = femaleCounter60.ToString();
                pos++;*/

                //sheet.Table.Rows.Insert(position, Row);

                position++;
            }
            

        }

        private List<List<Diagnos>> GenerateRowsFilterPatientsThisYear()
        {
            //TO DO: 21 row

            #region GenerateListOfRowsFilter

            List<List<Diagnos>> RowsFilter = new List<List<Diagnos>>();

            //checked
            var diagnos = DbContext.Instance.Diagnos.ToList();

            #region row01

            var list =
                diagnos.Where(d => (d.MKB.CompareTo("F00") >= 0 && d.MKB.CompareTo("F10") < 0) ||
                                   (d.MKB.CompareTo("F20") >= 0 && d.MKB.CompareTo("F100") < 0)).ToList();


            RowsFilter.Add(list);

            #endregion

            //checked

            #region row02

            list =
                diagnos.Where(d => d.MKB.CompareTo("F00") >= 0 && d.MKB.CompareTo("F10") < 0).ToList();
            RowsFilter.Add(list);

            #endregion

            //checked

            #region row03

            list =
                diagnos.Where(d => (d.MKB.CompareTo("F00") >= 0 && d.MKB.CompareTo("F06.34") < 0) ||
                                   (d.MKB.CompareTo("F06.81") >= 0 && d.MKB.CompareTo("F06.82") < 0) ||
                                   (d.MKB.CompareTo("F06.91") >= 0 && d.MKB.CompareTo("F06.92") < 0) ||
                                   (d.MKB.CompareTo("F09") >= 0 && d.MKB.CompareTo("F10") < 0)
                    ).ToList();
                

            RowsFilter.Add(list);

            #endregion

            //not already checked

            #region row04

            list =
                diagnos.Where(d => (d.MKB.CompareTo("F00") >= 0 && d.MKB.CompareTo("F02.4") < 0) ||
                                   (d.MKB.CompareTo("F03.1") >= 0 && d.MKB.CompareTo("F03.5") < 0))
                    .ToList();
                
            RowsFilter.Add(list);

            #endregion

            // this diagnosis are to be found

            #region row05

            list =
                diagnos.Where(d => d.MKB.CompareTo("F02.802*") >= 0 && d.MKB.CompareTo("F02.842*") <= 0).ToList();
               
            {
                var mkbName = new[]
                                  {
                                      "F04.2", "F05.02", "F05.12", "F05.82", "F05.92",
                                      "F06.02", "F06.12", "F06.22", "F06.302", "F06.312",
                                      "F06.322", "F06.332", "F06.812", "F06.912"
                                  };
                list.AddRange(DbContext.Instance.Diagnos.Where(d => mkbName.Any(mkb => mkb == d.MKB)));
            }

            RowsFilter.Add(list);

            #endregion

            //checked

            #region row06

            list =
                diagnos.Where(d => (d.MKB.CompareTo("F06.34") >= 0 && d.MKB.CompareTo("F06.38") < 0) ||
                                   (d.MKB.CompareTo("F06.4") >= 0 && d.MKB.CompareTo("F06.8") < 0) ||
                                   (d.MKB.CompareTo("F06.82") >= 0 && d.MKB.CompareTo("F06.9") < 0) ||
                                   (d.MKB.CompareTo("F06.92") >= 0 && d.MKB.CompareTo("F07") < 0) ||
                                   (d.MKB.CompareTo("F07") >= 0 && d.MKB.CompareTo("F08") < 0)).ToList();
                
            RowsFilter.Add(list);

            #endregion

            //checked

            #region row07

            list = new List<Diagnos>();
            {

                var mkbName = new[]
                                  {
                                      "F06.342", "F06.352", "F06.362", "F06.372", "F06.42", "F06.992",
                                      "F06.62", "F06.72", "F06.822", "F06.922", "F07.02",
                                      "F07.82", "F07.92"
                                  };
                list.AddRange(DbContext.Instance.Diagnos.Where(d => mkbName.Any(mkb => mkb == d.MKB)));
            }
            RowsFilter.Add(list);

            #endregion

            //checked

            #region row08

            list =
                diagnos.Where(d => d.MKB.CompareTo("F20") >= 0 && d.MKB.CompareTo("F21") < 0).ToList();
            RowsFilter.Add(list);

            #endregion

            //checked

            #region row09

            list =
                diagnos.Where(d => d.MKB.CompareTo("F21") >= 0 && d.MKB.CompareTo("F22") < 0).ToList();
            RowsFilter.Add(list);

            #endregion

            //checked

            #region row10

            list =
                diagnos.Where(d => d.MKB.CompareTo("F25") >= 0 && d.MKB.CompareTo("F26") < 0).ToList();
            RowsFilter.Add(list);

            #endregion

            //checked

            #region row11

            list =
                diagnos.Where(d => d.MKB.CompareTo("F23") >= 0 && d.MKB.CompareTo("F25") < 0).ToList();
            RowsFilter.Add(list);

            #endregion
            //checked
            #region row12

            list =
                diagnos.Where(d => (d.MKB.CompareTo("F22") >= 0 && d.MKB.CompareTo("F23") < 0) ||
                                   (d.MKB.CompareTo("F84.0") >= 0 && d.MKB.CompareTo("F84.5") < 0)).ToList();
                
            
            list.Add(DbContext.Instance.Diagnos.Where(d => d.MKB == "F99").FirstOrDefault());
            
            {

                var mkbName = new[] {"F28", "F29", "F80.31", "F99.1"};
                list.AddRange(DbContext.Instance.Diagnos.Where(d => mkbName.Any(mkb => mkb == d.MKB)));
            }

            RowsFilter.Add(list);

            #endregion
            //checked
            #region row13
            list =
                diagnos.Where(d => (d.MKB.CompareTo("F30.23") >= 0 && d.MKB.CompareTo("F30.28") <= 0) ||
                                   (d.MKB.CompareTo("F31.23") >= 0 && d.MKB.CompareTo("F31.28") <= 0) ||
                                   (d.MKB.CompareTo("F31.53") >= 0 && d.MKB.CompareTo("F31.58") <= 0) ||
                                   (d.MKB.CompareTo("F32.33") >= 0 && d.MKB.CompareTo("F32.38") <= 0) ||
                                   (d.MKB.CompareTo("F33.33") >= 0 && d.MKB.CompareTo("F33.38") <= 0) ||
                                   (d.MKB.Equals("F39"))).ToList();
            RowsFilter.Add(list);
                
            #endregion
            //checked
            #region row14
            list = new List<Diagnos>();
            {

                var mkbName = new[] { "F30.24", "F31.24", "F31.54", "F32.34", "F33.34" };
                list.AddRange(DbContext.Instance.Diagnos.Where(d => mkbName.Any(mkb => mkb == d.MKB)));
            }
       
            RowsFilter.Add(list);
            #endregion
            //checked
            #region row15
            list =
                diagnos.Where(d => (d.MKB.CompareTo("F32.00") >= 0 && d.MKB.CompareTo("F32.3") < 0) ||
                                   (d.MKB.CompareTo("F33.00") >= 0 && d.MKB.CompareTo("F33.3") < 0)).ToList();
                
            
            {
               
                var mkbName = new[] { "F30.0", "F30.1", "F30.8", "F30.9", "F31.0", "F31.1", "F31.3", "F31.30",
                    "F31.31", "F31.4", "F31.6", "F31.7", "F31.7", "F31.8", "F31.9", "F32.8", "F32.9", "F33.4",
                    "F33.8", "F33.9", "F34.0", "F34.1", "F34.8", "F34.9" };
                list.AddRange(DbContext.Instance.Diagnos.Where(d => mkbName.Any(mkb => mkb == d.MKB)));
            }

            RowsFilter.Add(list);
            #endregion
            //checked
            #region row16
            list =
                diagnos.Where(d => d.MKB.CompareTo("F40") >= 0 && d.MKB.CompareTo("F49") < 0).ToList();
            RowsFilter.Add(list);
            #endregion
            //checked
            #region row17
            list =
                diagnos.Where(d => (d.MKB.CompareTo("F50") >= 0 && d.MKB.CompareTo("F60") < 0) ||
                                   (d.MKB.CompareTo("F80.0") >= 0 && d.MKB.CompareTo("F80.3") < 0) ||
                                   (d.MKB.CompareTo("F80.32") >= 0 && d.MKB.CompareTo("F84") < 0) ||
                                   (d.MKB.CompareTo("F84.5") >= 0 && d.MKB.CompareTo("F99") < 0) ||
                                   (d.MKB.CompareTo("F99.2") >= 0 && d.MKB.CompareTo("F99.9") < 0)).ToList();
                
            
            RowsFilter.Add(list);

            #endregion
            //checked
            #region row18
            list =
                diagnos.Where(d => d.MKB.CompareTo("F60") >= 0 && d.MKB.CompareTo("F70") < 0).ToList();
            RowsFilter.Add(list);
            #endregion
            //checked
            #region row19
            list =
                diagnos.Where(d => d.MKB.CompareTo("F70") >= 0 && d.MKB.CompareTo("F71") < 0).ToList();
            RowsFilter.Add(list);
            #endregion

            #region row20
            list =
                diagnos.Where(d => d.MKB.CompareTo("F71") >= 0 && d.MKB.CompareTo("F80") < 0).ToList();
            RowsFilter.Add(list);
            #endregion
            //TODO:
            #region row21

            #endregion

            return RowsFilter;

            #endregion
        }
    }
}
